from openpyxl import load_workbook

workbook = load_workbook(filename="/home/thseus/workspaces/python/哈喽.xlsx")
sheet = workbook.active
print(sheet)
# sheet["A1"] = "哈喽"
# 这句代码也可以改为 cell = sheet["A1"] cell.value = "哈喽"
# workbook.save(filename="/home/thseus/workspaces/python/哈喽.xlsx")
"""
注意:我们将“A1”单元格的数据改为了“哈喽”,并另存为了“哈
喽.xlsx”文件。 如果我们保存的时候,不修改表名,相当于直接修改源文
件;
"""
# data = [
# ["唐僧","男","180cm"],
# ["孙悟空","男","188cm"],
# ["猪八戒","男","175cm"],
# ["沙僧","男","176cm"],
# ]
# for row in data:
#     sheet.append(row)

# 这是我们在 excel 中输入的公式
# =IF(RIGHT(C2,2)="cm",C2,SUBSTITUTE(C2,"m","")*100&"cm")
# 那么,在 python 中怎么插入 excel 公式呢?

# sheet["D1"] = "标准身高"
#
# for i in range(2,16):
#     sheet["D{}".format(i)] ='=IF(RIGHT(C{},2)="cm",C{},SUBSTITUTE(C{},"m","")*100&"cm")'.format(i,i,i)

workbook.save(filename = "/home/thseus/workspaces/python/哈喽.xlsx")